﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AspNetCs.Model;
using AspNetCs.Bll;
using System.Data;
using System.Collections;
using AspNetCs.Enumerations;
using AspNetCs.Enumerations.memorial_enum;
using AspNetCs.Enumerations.User_Enum;
using AspNetCs.Common;
using AspNetCs.Enumerations.Channel_Enum;

public partial class Users_AddAncestralHallBackMusic :BasePage
{
    protected int AncestralHallId = 0;
    private AncestralHallItemsBLL bll = new AncestralHallItemsBLL();
    private AncestralHallBLL anll = AncestralHall_Bll.CreatNew;
    private AncestralHall_Model model = new AncestralHall_Model();

    protected string notSet = "display:none;";
    protected string play = "display:block;";
    protected string musicPath = "";
    protected int MusicId = 0;

    protected void Page_Load(object sender, EventArgs e)
    {
        CheckUserExit("Login.Aspx", "请您登录", true);

        if (!IsPostBack)
        {
            if (string.IsNullOrEmpty(Request["id"]))
            {
                ResultStr("Login.aspx", "参数错误");
            }
            else
            {
                ViewState["Id"] = Request["id"];
                this.AncestralHallId = StringHelper.isNumber_int(Request["id"]);
                DataTable dataTable=anll.GetAncestralHallInfoById(AncestralHallId);
                
                if(dataTable.Rows.Count>0)
                {
                     MusicId=StringHelper.isNumber_int(dataTable.Rows[0]["MusicId"].ToString());
                }

                MusicBLL musicBLL = new MusicBLL();
                musicBLL.BindSelectedMusic(MusicId, ddlMusic);
            }
        }
        else
        {
            if (ViewState["Id"] != null)
            {
                this.AncestralHallId = StringHelper.isNumber_int(ViewState["Id"].ToString());
                DataTable dataTable = anll.GetAncestralHallInfoById(AncestralHallId);

                if (dataTable.Rows.Count > 0)
                {
                    MusicId = StringHelper.isNumber_int(dataTable.Rows[0]["MusicId"].ToString());
                }
            }
        }
        initMusic();
    }

    public void initMusic()
    {
        if (MusicId == 0)
        {
            notSet = "display:block;";
            play = "display:none;";
        }
        else
        {
            MusicBLL musicBll = Music_Bll.CreateNew;
            MusicModel musicModel = new MusicModel();
            DataTable dataTable = musicBll.GetDataTable("id=" + MusicId);
            if (dataTable.Rows.Count > 0)
            {
                musicModel = musicBll.GetModel(dataTable.Rows[0]);
            }
            if (musicModel.MusicType == 0)
            {
                musicPath = "../" + musicModel.MusicPath;
            }
            else
            {
                musicPath = musicModel.MusicPath;
            }
        }
    }

    protected void btnMusic_Click(object sender, EventArgs e)
    {
        int MusicId = StringHelper.isNumber_int(ddlMusic.SelectedValue);
        //if (MusicId > 0)
        //{
            anll.SetMusic(AncestralHallId, MusicId);
        //}
            Response.Redirect("AddAncestralHallBackMusic_" + AncestralHallId + ".Aspx");
    }
}
